package com.guigu.dispatch.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.dispatch.entity.OrderClassifyAttach;
import com.guigu.dispatch.entity.OrderClassifyAttachDTO;
import com.guigu.dispatch.service.OrderClassifyAttachService;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 车次车辆司机订单分类关联表 前端控制器
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-18
 */
@RestController
@RequestMapping("/dispatch/order-classify-attach")
public class OrderClassifyAttachController {

    private OrderClassifyAttachService orderClassifyAttachService;

    public OrderClassifyAttachController(OrderClassifyAttachService orderClassifyAttachService) {
        this.orderClassifyAttachService = orderClassifyAttachService;
    }

    /**
     * 根据订单分类Id查询所对应的车次车辆司机
     *
     * @param orderClassifyId
     * @return
     */
    @ApiOperation("根据订单分类Id查询所对应的车次车辆司机")
    @GetMapping("/getOrderClassifyAttachById/{orderClassifyId}")
    public R<OrderClassifyAttach> getOrderClassifyAttachById(@PathVariable("orderClassifyId") String orderClassifyId) {
        QueryWrapper<OrderClassifyAttach> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_classify_id", orderClassifyId);
        OrderClassifyAttach attach = orderClassifyAttachService.getOne(queryWrapper);
        if (ObjectUtils.isEmpty(attach)) {
            return new R<>(ResultCode.ERROR_CODE, null);
        }
        return new R<>(ResultCode.SUCCESS_CODE, attach);
    }

    /**
     * 添加订单分类车辆司机车次关联表以及订单分类和线路的中间表
     *
     * @param dto
     * @return
     */
    @ApiOperation("添加订单分类车辆司机车次关联表以及订单分类和线路的中间表")
    @ApiImplicitParam(name = "dto", value = "订单分类的数据传输对象")
    @PostMapping("/orderClassifyTripsTruckDriverAdd")
    public R orderClassifyTripsTruckDriverAdd(@RequestBody OrderClassifyAttachDTO dto) {
        R r = orderClassifyAttachService.orderClassifyTripsTruckDriverAdd(dto);
        return r;

    }
}

